require.config({
	paths: {
		"jquery" : "jquery-1.11.3",
		"cookie" : "jquery.cookie",
		"swiper" :　"swiper-3.4.2.jquery.min"
	}
})
require(["jquery","cookie","swiper"],function($,cookie,swiper){
//	图片动态更新部分
	$.getJSON("json/index.json",function(data){
		//$(".left-logo > img").attr({"src":"img/indeximg/" + data.index.logo[1]});
		//$(".right-logo > img").attr({"src":"img/indeximg/" + data.index.logo[0]});
//		logo部分
		var $logo = $(".logo-container img");
		var $logoNum = 0;
		$logo.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.logo[$logoNum ++]});
		})
		
//		banner图部分
		var $banner = $(".swiper-container img");
		var $bannerNum = 0;
		$banner.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.slideShow[$bannerNum ++]});
		})
//		业务分类部分
		var $business = $(".business-item img");
		var $businessNum = 0;
		$business.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.business[$businessNum ++]});
		})
//		特别推荐
		var $topic = $(".topic-list img");
		var $topicNum = 0;
		$topic.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.topic[$topicNum ++]});
		})
//		热卖榜
		var $hotSale = $(".hot-list img");
		var $hotSaleNum = 0;
		$hotSale.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.hotSale[$hotSaleNum ++]})
		})
//		实体店
		var $storeInfoContainer = $(".storeInfoContainer img");
		$storeInfoContainer.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.storeInfoContainer[0]});
		})
		
		var $storeActive = $(".store-active img");
		$storeActive.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.storeActive[0]});
		})
		
		var $storeList = $(".list-item img");
		var $storeListNum = 0;
		$storeList.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.storeList[$storeListNum ++]});
		})
//		楼层部分
		var $floorMain = $(".floor-main img");
		var $floorNum = 0;
		$floorMain.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.floorMain[$floorNum ++]});
		})
		var $goodsList = $(".goods-list img");
		var $goodsListNum = 0;
		$goodsList.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.goodsList[$goodsListNum ++]});
		})
//		分类导航部分
		var $classification = $(".classification img");
		var $classificationNum = 0;
		$classification.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.classification[$classificationNum ++]});
		})
		var $slider = $(".slider img");
		var $sliderNum = 0;
		$slider.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.rollArea[$sliderNum ++]});
		})
		var $qrcode = $(".qrcode img");
		var $qrcodeNum = 0;
		$qrcode.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.qrcode[$qrcodeNum ++]});
		})
		var $certification = $(".certification img");
		var $certificationNum = 0;
		$certification.each(function(){
			$(this).attr({"src":"img/indeximg/" + data.index.certification[$certificationNum ++]});
		})
	})
//	头部导航部分 鼠标滑过变色
	$(".top-color").hover(function(){
		$(this).css("color","#f60");
	},function(){
		$(this).css("color","#99918b");
	})
//  头部定位
	$(function(){
		$(window).scroll(function(){
			var $t = $(this).scrollTop();
			if($t > 300){
				$("#headFixContainer").css("display","block");
			}else{
				$("#headFixContainer").css("display","none");
			}
		})
	})
//	购物车部分
	$(".cart").click(function(){
		location.href = "html/cart.html";
	})
//  二级菜单部分	
	$(function(){
		var $a = $(".cate-title");
		var $leave1 = $(".submenu");
		var $leave2 = $(".cate-aside");
		
		$a.mouseover(function(){
			$leave1.css("display","block");
		});
		$leave1.mouseover(function(){
			$leave2.css("display","block");
		});
		$leave2.mouseout(function() {
			$leave1.css("display", "none");
			$leave2.css("display", "none");
		});
	})
//	轮播图部分
	$(document).ready(function(){
		var mySwiper = new Swiper(".swiper-container",{
			direction:"horizontal",
			loop:true,
			autoplay:2000,
		    autoplayDisableOnInteraction:false,
	//		分页器
			pagination:".swiper-pagination",
			paginationClickable:"true",
	//		按钮
			nextButton:".swiper-button-next",
			prevButton:".swiper-button-prev",
		})	
	})
//	分类
	$(function(){
		var $businessItem = $(".jq-business1 img");
		for(var i = 0;i < $businessItem.length;i ++){
			$businessItem.eq(i).mouseover(function(){
				$(this).animate({top:"-10px"},"fast");
			});
			$businessItem.eq(i).mouseout(function(){
				$businessItem.animate({top:"0px"},"fast");
			});
		}	
	})
//	登录部分
	$(function(){
		var str = $("loginedUsers") ? $.cookie("loginedUsers") : "";
		if(str){
			var obj = convertStrToObj(str);
			$(".top-denglu").empty().append("欢迎" + str);
			$(".top-zhuce").empty().append("注销");
			$(".top-zhuce").click(function(){
				$.removeCookie("loginedUsers",{expires:7,path:"/"});
				$(this).empty().append("立即注册");
				$(".top-denglu").empty().append("登录");
				location.href = "index.html";
			})
		}else{
			$(".top-denglu").click(function(){
				location.href = "html/login.html";
			});
			$(".top-zhuce").click(function(){
				location.href = "html/register.html";
			})
		}		
	})
	function convertStrToObj(str){
		if(!str){
			return {};
		}
		var users = str.split(":");
		var obj = {};
		for(var i = 0; i < users.length; i ++){
			var data = users[i].split(",");
			obj[data[0]] = data[1];
		}
		return obj;
	}
	function convertObjToStr(obj){
		var str = "";
		for(var usn in obj){
			var pwd = obj[usn];
			if(str){
				str += ":";
			}
			str += usn + "," + pwd;
		}
		return str;
	}
//	特别推荐部分
	$(function(){
		var $topic = $(".topic a");
		var $topicImg = $(".topic-img");
//		for(var i = 0; i < $topic.length; i ++){
//			$topic.eq(i).hover(function(){
//				$topicImg.animate({
//					"width":"300px",
//					"height":"200px"
//				},1000)
//			},function(){
//				$topicImg.animate({
//					"width":"275px",
//					"height":"170px"
//				},1000)
//			})
//		}
		$topic.each(function(){
			$(this).hover(function(){
				$(this).find("img").animate({
					"width":"300px",
					"height":"200px"
				})
			},function(){
				$(this).find("img").animate({
					"width":"275px",
					"height":"170px"
				})
			})
		})
	})
})
















